package com.netease.dragonwar.util;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * 图片工具类
 */
public class ImageUtils {
	private static ClassLoader loader = Thread.currentThread().getContextClassLoader();

	/**
	 * 定义背景图片
	 */
	private static BufferedImage backImage = null;

	/**
	 * 定义游戏标题图片
	 */
	private static BufferedImage titleImage = null;

	/**
	 * 定义开始按钮图片
	 */
	private static BufferedImage startImage = null;

	/**
	 * 定义结束图片
	 */
	private static BufferedImage overImage = null;

	/**
	 * 定义重新开始图片
	 */
	private static BufferedImage restartImage = null;

	/**
	 * 定义英雄图片集
	 */
	private static BufferedImage[][] heroImages = null;

	/**
	 * 定义敌人图片集
	 */
	private static BufferedImage enemyImage = null;

	/**
	 * 定义子弹图片集
	 */
	private static BufferedImage[] bulletImages = null;

	static {
		try {
			backImage = ImageIO.read(loader.getResourceAsStream("res/img/background/bg1.png"));
			titleImage = ImageIO.read(loader.getResourceAsStream("res/img/background/gameTitle.png"));
			startImage = ImageIO.read(loader.getResourceAsStream("res/img/background/gameStart.png"));
			overImage = ImageIO.read(loader.getResourceAsStream("res/img/background/gameOver.png"));
			restartImage = ImageIO.read(loader.getResourceAsStream("res/img/background/gameRestart.png"));

			BufferedImage upImg0 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroUp0.png"));
			BufferedImage upImg1 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroUp1.png"));
			BufferedImage upImg2 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroUp2.png"));
			BufferedImage[] upImgs = new BufferedImage[]{upImg0, upImg1, upImg2};

			BufferedImage rightImg0 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroRight0.png"));
			BufferedImage rightImg1 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroRight1.png"));
			BufferedImage rightImg2 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroRight2.png"));
			BufferedImage[] rightImgs = new BufferedImage[]{rightImg0, rightImg1, rightImg2};

			BufferedImage downImg0 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroDown0.png"));
			BufferedImage downImg1 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroDown1.png"));
			BufferedImage downImg2 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroDown2.png"));
			BufferedImage[] downImgs = new BufferedImage[]{downImg0, downImg1, downImg2};

			BufferedImage leftImg0 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroLeft0.png"));
			BufferedImage leftImg1 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroLeft1.png"));
			BufferedImage leftImg2 = ImageIO.read(loader.getResourceAsStream("res/img/hero/heroLeft2.png"));
			BufferedImage[] leftImgs = new BufferedImage[]{leftImg0, leftImg1, leftImg2};
			heroImages = new BufferedImage[][]{upImgs, rightImgs, downImgs, leftImgs};


			BufferedImage upImage = ImageIO.read(loader.getResourceAsStream("res/img/bullet/bulletUp.png"));
			BufferedImage rightImage = ImageIO.read(loader.getResourceAsStream("res/img/bullet/bulletRight.png"));
			BufferedImage downImage = ImageIO.read(loader.getResourceAsStream("res/img/bullet/bulletDown.png"));
			BufferedImage leftImage = ImageIO.read(loader.getResourceAsStream("res/img/bullet/bulletLeft.png"));
			bulletImages = new BufferedImage[]{upImage, rightImage, downImage, leftImage};


			enemyImage = ImageIO.read(loader.getResourceAsStream("res/img/enemy/enemy.png"));

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static BufferedImage getBackImage() {
		return backImage;
	}

	public static BufferedImage getTitleImage() {
		return titleImage;
	}

	public static BufferedImage getStartImage() {
		return startImage;
	}

	public static BufferedImage getOverImage() {
		return overImage;
	}

	public static BufferedImage getRestartImage() {
		return restartImage;
	}

	public static BufferedImage[][] getHeroImages() {
		return heroImages;
	}

	public static BufferedImage[] getBulletImages() {
		return bulletImages;
	}

	public static BufferedImage getEnemyImage() {
		return enemyImage;
	}
}
